
Namespace std
    Public Class queue(Of valueT, store As linearContainer(Of valueT))
        Implements ICloneable

        'for keeping the erase logic in queue(of valueT)
        Protected data As store = Nothing

        Public Sub clear()
            data.clear()
        End Sub

        Public Function empty() As Boolean
            Return data.empty()
        End Function

        Public Function size() As Int64
            Return data.size()
        End Function

        Public Function front() As valueT
            Return data.front()
        End Function

        Public Function back() As valueT
            Return data.back()
        End Function

        Public Sub push(ByVal dataNew As valueT)
            data.push_back(dataNew)
        End Sub

        Public Sub pop()
            data.pop_front()
        End Sub

        Public Overridable Function Clone() As Object Implements System.ICloneable.Clone
            Return New queue(Of valueT, store)(data)
        End Function

        Protected Overridable Function generateData() As store
            Return alloc(Of store)()
        End Function

        Public Sub New(ByVal that As queue(Of valueT, store))
            copy(data, that.data)
        End Sub

        Public Sub New(ByVal that As store)
            copy(data, that)
        End Sub

        Public Sub New()
            data = generateData()
        End Sub
    End Class

    Public Class queue(Of valueT)
        Inherits queue(Of valueT, list(Of valueT))

        Protected Overrides Function generateData() As list(Of valueT)
            Return New list(Of valueT)()
        End Function

        Public Sub New(ByVal that As queue(Of valueT))
            MyBase.New(that)
        End Sub

        Public Sub New(ByVal that As list(Of valueT))
            MyBase.New(that)
        End Sub

        Public Sub New()
            MyBase.New()
        End Sub

        Public Overrides Function Clone() As Object
            'avoid to use data here, as it should be private
            Return New queue(Of valueT)(Me)
        End Function

        'in fact, there should be no such function, but it's here, so leave them
        Public Function [erase](ByVal start As Int64, ByVal [end] As Int64) As Boolean
            While start < [end] AndAlso Not data.erase(start) Is Nothing
                start += 1
            End While

            Return start = [end]
        End Function

        Public Function [erase](ByVal start As Int64) As Boolean
            Return [erase](start, start + 1)
        End Function
    End Class
End Namespace
